<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <!-- 中间的tabs切换 -->
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <!-- 1.账号登录的Pane -->
        <el-tab-pane name="account">
          <!--使用label具名插槽-->
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">帐号登录</span>
            </div>
          </template>
          <!-- 账户登录组件 -->
          <PanelAccount ref="accountRef" />
        </el-tab-pane>

        <!-- 2.手机登录的Pane -->
        <el-tab-pane name="phone">
          <template #label>
            <div class="label">
              <el-icon><Cellphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <!--手机登录组件 -->
          <PanelPhone />
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 底部区域 -->
    <div class="controls">
      <el-checkbox v-model="isRemPwd" label="记住密码" size="large" @change="changeisRemPwd" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="login-btn" type="primary" size="large" @click="handleLoginBtnClick"> 立即登录 </el-button>
  </div>
</template>

<script lang="ts" setup>
import { localCache } from '@/utils/storage'
import PanelAccount from './PanelAccount.vue'
import PanelPhone from './PanelPhone.vue'

import { ref } from 'vue'

//默认是账户登录
let activeName = ref<string>('account')

//是否记住密码
let isRemPwd = ref<boolean>(localCache.getStorage('isRemPwd') == 'true' ?? false)

const accountRef = ref<InstanceType<typeof PanelAccount>>()

/**
 * 切换记住密码(localStorage不支持传布尔类型，所以转化成字符串)
 */
function changeisRemPwd(val) {
  localCache.setStorage('isRemPwd', JSON.stringify(val))
}

/**
 * 登录
 */
function handleLoginBtnClick() {
  if (activeName.value == 'account') {
    accountRef.value?.loginOpt(isRemPwd.value)
  } else {
    console.log('用户正在进行手机登录')
  }
}
</script>

<style lang="less" scoped>
.login-panel {
  width: 450px;
  margin-bottom: 150px;
  .title {
    text-align: center;
    margin-bottom: 15px;
  }
  .label {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }
  .controls {
    margin-top: 12px;
    display: flex;

    justify-content: space-between;
  }
  .login-btn {
    margin-top: 10px;
    width: 100%;
    // --el-button-size: 50px;
  }
}
</style>
